home *** CD-ROM | disk | FTP | other *** search
- Glydo.DetachedPopupsManager = Prototype.Class.create(Glydo.EventSource,{
-
- initialize: function($super,application) {
- $super();
- this.openedPopup = null;
- this.detachedWindows = {};
- this.application = application;
- this.panel = document.getElementById("glydo-recommendations-popup");
- this.panelTitle = document.getElementById("glydo-vertical-pane-title")
- this.panelRecommendationsView = document.getElementById("glydo-recpopup-recommendations-view");
- this.onPanelHoverEnter = Prototype.F.bindAsEventListener(Prototype.F.curry(this.onPanelHover,true),this);
- this.onPanelHoverExit = Prototype.F.bindAsEventListener(Prototype.F.curry(this.onPanelHover,false),this);
- },
-
- openDetachedWindow: function(defs,options) {
- // If a detached window with this name is already open, bring it to focus
- var win = this.detachedWindows[defs.name];
- if (win) {
- win.focus();
- return;
- }
-
- var features = "chrome,dialog=no,titlebar=no,close=no,alwaysRaised=yes";
- if (Glydo.Utils.platformShort() == 'mac') {
- features = "dialog=no, chrome, resizable=no,dependent=yes";
- }
-
- var screenX = options.anchor.boxObject.screenX + options.anchor.boxObject.width - 250 - 1 - 30;
- var screenY = options.anchor.boxObject.screenY - 3 - 384 - 30;
- if (options.from_popup) {
- screenX = options.from_popup.boxObject.x - 30;
- screenY = options.from_popup.boxObject.y - 30;
- }
-
- features += ",top=" + screenY + ",left=" + screenX;
-
- win = window.openDialog("chrome://glydo/content/ui/recommendations/vertical_pane_xul/vertical_pane_window.xul",
- "_blank",
- features,
- this.application,
- defs.filter,
- defs.title,
- defs.name);
- Glydo.Utils.addListener(win,"load", Prototype.F.curry(this.onWindowLoaded,defs.name), this, false);
- this.detachedWindows[defs.name] = win;
- },
-
- closeDetachedWindow: function(name) {
- var win = this.detachedWindows[name];
- if (!win) {
- return false;
- }
- win.close();
- return true;
- },
-
- toggleDetachedWindow: function(defs,options) {
- var win = this.detachedWindows[defs.name];
- if (win) {
- this.closeDetachedWindow(defs.name);
- } else {
- this.openDetachedWindow(defs,options);
- }
- },
-
- toggleDetachedWindowAndHidePopup: function(defs,options) {
- var win = this.detachedWindows[defs.name];
- if (win) {
- this.closeDetachedWindow(defs.name);
- } else {
- this.closePopup(null,Glydo.DetachedPopupsManager.CLOSE_REASONS.DETACHED);
- this.openDetachedWindow(defs,options);
- }
- },
-
- onWindowLoaded: function(name,event) {
- var win = event.currentTarget;
- // The following can't work this easily, the window starts of
- // with size 1. We need to track resizes if we want to do this
- // properly, but only if the window was just opened
- //var w = win.outerWidth;
- //var h = win.outerHeight;
- //var x = Math.max(win.screen.availLeft,Math.min(win.screen.availLeft + win.screen.availWidth,right)-w);
- //var y = Math.max(win.screen.availTop,Math.min(win.screen.availTop + win.screen.availHeight,bottom)-h);
- Glydo.Utils.addListener(win,"unload", Prototype.F.curry(this.onWindowUnloaded,name), this, false);
- this.fire('onDetachedWindowOpened',name);
- },
-
- onWindowUnloaded: function(name,event) {
- delete this.detachedWindows[name];
- this.fire('onDetachedWindowClosed',name);
- },
-
- openPopup: function(defs,options) {
- options = options || {};
- // If a popup with another name is already open, close it.
- if (this.openedPopup) {
- if (defs.name == this.openedPopup.defs.name) {
- return;
- }
- this.closePopup(null,Glydo.DetachedPopupsManager.CLOSE_REASONS.OPENED_ANOTHER);
- }
- var recViewClassesMap = defs["recViewClassesMap"] || Glydo.RECOMMENDATION_VIEW_CLASSES_MAP;
- var controller = new Glydo.VerticalPaneController(recViewClassesMap);
- // Record and open the popup
- this.openedPopup = {
- defs: defs,
- popup: this.panel,
- controller: controller,
- anchor: options.anchor,
- openTime: new Date(),
- autoHideInterval: options.auto_hide,
- autoHideTimer: null
- };
- position = options.position || "before_start";
- // Fix position if overflowing browser window on the right,
- // to reduce the effect of the firefox bug that ignores the
- // available screen area when opening non-auto-hide popups
- var excess = 0;
- if (options.anchor && options.ensureContainedWidth) {
- // FIXME: Make this work regardless of the position used
- excess = options.ensureContainedWidth - window.innerWidth + options.anchor.boxObject.x;
- excess = (excess > 0) ? excess : 0;
- }
- var contentsType = (defs.contentsType || defs.name);
- Prototype.E.addClassName(this.panel,"glydo-vertical-pane-"+defs.name);
- Prototype.E.addClassName(this.panel,"glydo-vertical-pane-contains-"+ contentsType);
- if (options.realEstateKind) {
- this.panel.setAttribute("realEstateKind",options.realEstateKind);
- }
- this.panelTitle.setAttribute("value",defs.title);
- // Initialize the controller
- controller.init("recpopup",this.application,defs.filter,defs.adFilter,defs.name);
- controller.addListener(this);
- this.panel.openPopup(options.anchor,position,-excess,-3);
- this.panel.addEventListener('mouseover',this.onPanelHoverEnter,false);
- this.panel.addEventListener('mouseout',this.onPanelHoverExit,false);
- var tags = ({
- type: "popup",
- name: defs.name,
- contains: contentsType
- });
- Glydo.LOGGING_DB.logUserEvent(
- "recommendations_pane",
- "open", tags, null);
- this.startAutoHideTimerIfNecessary();
- },
-
- startAutoHideTimerIfNecessary: function() {
- if (this.openedPopup && this.openedPopup.autoHideInterval && !this.openedPopup.autoHideTimer) {
- this.openedPopup.autoHideTimer = setTimeout(Prototype.F.bind(Prototype.F.curry(this.closePopup,this.openedPopup.defs.name,Glydo.DetachedPopupsManager.CLOSE_REASONS.AUTO_HIDE),this),this.openedPopup.autoHideInterval);
- }
- },
-
- stopAutoHideTimerIfNecessary: function() {
- if (this.openedPopup && this.openedPopup.autoHideTimer) {
- clearTimeout(this.openedPopup.autoHideTimer);
- this.openedPopup.autoHideTimer = null;
- }
- },
-
- onPanelHover: function(enter,event) {
- if (!this.openedPopup) {
- return;
- }
- if (enter) {
- if (this.openedPopup.hover) {
- return;
- }
- } else {
- if (event.relatedTarget !== null) {
- if (Prototype.E.descendantOf(event.relatedTarget,this.openedPopup.popup)) {
- return;
- }
- }
- if (!this.openedPopup.hover) {
- return;
- }
- }
- this.openedPopup.hover = !this.openedPopup.hover;
- if (this.openedPopup.hover) {
- this.stopAutoHideTimerIfNecessary();
- } else {
- this.startAutoHideTimerIfNecessary();
- }
- },
-
- closePopup: function(name,reason) {
- if (!this.openedPopup) {
- return;
- }
- if (!name || (this.openedPopup.defs.name == name)) {
- // We need to destroy the controller
- this.openedPopup.controller.destroy();
- this.openedPopup.hideReason = reason;
- this.openedPopup.popup.hidePopup();
- }
- },
-
- togglePopup: function(defs,options) {
- if (!this.openedPopup) {
- this.openPopup(defs,options);
- return true;
- } else {
- if (this.openedPopup.defs.name == defs.name) {
- this.closePopup(null,Glydo.DetachedPopupsManager.CLOSE_REASONS.USER_CLOSE);
- return false;
- } else {
- this.openPopup(defs,options);
- return true;
- }
- }
- },
-
- focusWindowOrTogglePopup: function(defs,options) {
- var win = this.detachedWindows[defs.name];
- if (win) {
- win.focus();
- return true;
- } else {
- return this.togglePopup(defs,options);
- }
- },
-
- onPopupShowing: function(event) {
- if (!this.openedPopup) {
- return;
- }
- this.fire('onPopupOpening',this.openedPopup.defs.name);
- },
-
- onPopupShown: function(event) {
- if (!this.openedPopup) {
- return;
- }
- this.openedPopup.controller.onVisible();
- this.fire('onPopupOpened',this.openedPopup.defs.name);
- },
-
- onPopupHiding: function(event) {
- },
-
- onPopupHidden: function(event) {
- if (!this.openedPopup) {
- return;
- }
- if (this.openedPopup.autoHideTimer) {
- clearTimeout(this.openedPopup.autoHideTimer);
- }
- var name = this.openedPopup.defs.name;
- var reason = this.openedPopup.hideReason;
- var openTime = this.openedPopup.openTime;
- var contentsType = this.openedPopup.defs.contentsType;
- contentsType = contentsType || name;
- Prototype.E.removeClassName(this.panel,"glydo-vertical-pane-"+name);
- Prototype.E.removeClassName(this.panel,"glydo-vertical-pane-contains-"+ contentsType);
- this.panel.removeAttribute("realEstateKind");
- this.panelTitle.removeAttribute("value");
- this.openedPopup = null;
- this.fire('onPopupClosed',name,reason,(new Date().getTime()) - openTime.getTime());
- var tags = ({
- type: "popup",
- name: name,
- contains: contentsType
- });
- if (reason && reason.name) {
- tags.reason = reason.name;
- }
- Glydo.LOGGING_DB.logUserEvent(
- "recommendations_pane",
- "close", tags,
- (new Date().getTime()) - openTime.getTime());
- },
-
- detachPopup: function() {
- if (!this.openedPopup) {
- return;
- }
- var defs = this.openedPopup.defs;
- var anchor = this.openedPopup.anchor;
- this.openDetachedWindow(defs,anchor,this.openedPopup.popup);
- this.closePopup(null,Glydo.DetachedPopupsManager.CLOSE_REASONS.DETACHED);
- },
-
- onCurrentBrowserChanged: function(browser) {
- this.closePopup(null,Glydo.DetachedPopupsManager.CLOSE_REASONS.CHANGED_CONTEXT);
- },
-
- getContextRecommendation: function() {
- if (this.openedPopup) {
- return this.openedPopup.controller.getContextRecommendation();
- }
- },
-
- onContextMenu: function(event) {
- if (this.openedPopup) {
- return this.openedPopup.controller.onContextMenu(event);
- }
- return true;
- },
-
- isPopupOpen: function() {
- return !!this.openedPopup;
- },
-
- onCurrentProcessedDocumentChanged: function(docEntry) {
- this.closePopup(null,Glydo.DetachedPopupsManager.CLOSE_REASONS.CONTEXT_CHANGE);
- },
-
- onPopupCloseButtonClick: function() {
- var tags = ({
- type: "popup",
- });
- if (this.openedPopup) {
- var defs = this.openedPopup.defs;
- tags.name = defs.name;
- tags.contains = defs.contentsType || defs.name;
- }
- Glydo.LOGGING_DB.logUserEvent(
- "recommendations_pane.buttons.close",
- "click", tags,
- (new Date().getTime()) - this.openedPopup.openTime.getTime());
- this.closePopup(null,Glydo.DetachedPopupsManager.CLOSE_REASONS.USER_CLOSE)
- }
- });
-
- Glydo.DetachedPopupsManager.CLOSE_REASONS = ({
- USER_CLOSE: {
- name: "user_close",
- interaction: true
- },
- OPENED_ANOTHER: {
- name: "opened_another",
- interaction: true
- },
- DETACHED: {
- name: "detached",
- interaction: true
- },
- DOCKED: {
- name: "docked",
- interaction: true
- },
- AUTO_HIDE: {
- name: "auto_hide",
- interaction: false
- },
- CONTEXT_CHANGE: {
- name: "context_change",
- interaction: false
- }
- });
-